<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Session;
use \think\Db;
class Formpostcomment extends Common
{
	
  public function addpostcomment(){
    
    $this->assign('postid',input('postid'));
    
    return $this->fetch();
  }

  public function editpostcomment(){

    $comment = Db::name('postcomment')->where('comment_id',input('commentid'))->find();
    $this->assign('postcomment',$comment);
    return $this->fetch();

  }

  public function add(){
    $info = '';
     if(request()->isPost()){  
        $data=[
          'post_id'=>input('postid'),
          'user_id'=>0,
          'comment_content'=>input('content'),
          'comment_time'=>date('Y-m-d H:i:s'),
          'comment_like'=>0,
          'scan_status'=>1,
          'comment_status'=>1,
        ];
        $res=Db::name('postcomment')->insert($data);
        if ($res){
          $this->success("添加评论成功",'community/postcomment');
        }
        else {
          $this->error("添加评论失败");
        }
      }
  }



  public function edit(){
    $info = '';
     if(request()->isPost()){  
        $data=[
          'comment_content'=>input('content'),
        ];
        $res=Db::name('postcomment')->where('comment_id',input('commentid'))->update($data);
        if ($res!==false){
          $this->success("修改评论成功",'community/postcomment');
        }
        else {
          $this->error("修改失败");
        }
      }
  }

  public function delete(){
    $res = Db::name('postcomment')->where('comment_id',input('commentid'))->update(['postcomment_status'=>input('statu')]);
    if($res===false){
        $this->error("处理失败");
    }
    $this->redirect('community/postcomment');
  }

  
}